package model;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Describes a debate format, for example OPD or BPS.
 * 
 */
public class DebateFormat {

	private final String label;
	private final int minSpeakerCount;
	private final int maxSpeakerCount;
	private final List<SpeakerRole> speakerRolesForSpeakerCount;
	private final List<SpeakerRole> otherRoles;
	private final List<SpeakerRole> opRoles;
	private final List<SpeakerRole> govRoles;

	public DebateFormat(String label, int minSpeakerCount, int maxSpeakerCount,
			List<SpeakerRole> govRoles, List<SpeakerRole> opRoles,
			List<SpeakerRole> otherRoles,
			List<SpeakerRole> speakerRolesForSpeakerCount) {
		this.label = label;
		this.maxSpeakerCount = maxSpeakerCount;
		this.minSpeakerCount = minSpeakerCount;
		this.govRoles = govRoles;
		this.opRoles = opRoles;
		this.otherRoles = otherRoles;
		this.speakerRolesForSpeakerCount = speakerRolesForSpeakerCount;

	}

	public List<SpeakerRole> getOtherRoles() {
		return Collections.unmodifiableList(otherRoles);
	}

	public List<SpeakerRole> getOpRoles() {
		return Collections.unmodifiableList(opRoles);
	}

	public List<SpeakerRole> getGovRoles() {
		return Collections.unmodifiableList(govRoles);
	}

	public String getLabel() {
		return label;
	}

	public int getMinSpeakerCount() {
		return minSpeakerCount;
	}

	public int getMaxSpeakerCount() {
		return maxSpeakerCount;
	}

	public Set<SpeakerRole> getAllRoles() {
		Set<SpeakerRole> all = new HashSet<>();
		all.addAll(govRoles);
		all.addAll(opRoles);
		all.addAll(otherRoles);
		return all;
	}

	public List<SpeakerRole> getRolesForSpeakerCount(int speakerCount) {
		if (speakerCount > getMaxSpeakerCount()
				|| speakerCount < getMinSpeakerCount()) {
			throw new IllegalArgumentException("given speaker count ("
					+ speakerCount + ") is not supported");
		}
		return speakerRolesForSpeakerCount.subList(0, speakerCount);
	}

	@Override
	public String toString() {
		return label;
	}
}
